package org.car.world.controller;

import java.util.HashMap;
import java.util.Map;

import org.car.world.common.util.Page;
import org.car.world.core.entily.MerchantsTable;
import org.car.world.service.MerchantsService;
import org.car.world.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * @author Administrator
 * @ClassName: MerchantsController
 * @Description: 商家管理
 * @date Nov 9, 2018
 */

@Controller
@RequestMapping("admin")
/*@Transactional*/
public class MerchantsController {


    @Autowired
    MerchantsService merchantsService;


    @Autowired
    TypeService typeService;


    /**
     * @param @return 参数
     * @return String    返回类型
     * @throws
     * @Title: domerchants_init
     * @Description: 访问商户列表方法
     */
    @RequestMapping("domerchants")
    public String domerchants_method(@RequestParam(value = "form", required = false, defaultValue = "1") Integer form,
                                     @RequestParam(value = "merchantsState", required = false, defaultValue = "1") Integer merchantsState, Model mo) {


        Page<MerchantsTable> Page = new Page<MerchantsTable>();
        Page.setCurrentPage(form);
        Page.setPageSize(10);
        Page.setTotalRow(merchantsService.selectcount(merchantsState));
        Page.setPageList(merchantsService.selectLimit(Page.getCurrentPage(), Page.getPageSize(), merchantsState));
        mo.addAttribute("Page", Page);
        mo.addAttribute("typeList", typeService.selectAllidentify("TYPE_ISSUE"));
        mo.addAttribute("merchantsState", merchantsState);
        return "merchants_list";
    }

    /**
     * @param @return 参数
     * @return String    返回类型
     * @throws
     * @Title: domerchantsinfo_method
     * @Description: 查看商家信息页面
     */
    @RequestMapping("merchantsinfo")
    public String domerchantsinfo_method(Integer metid, Model mo) {
        MerchantsTable merchants = merchantsService.selectByPrimaryKey(metid);
        if (merchants != null) {
            mo.addAttribute("Merchants", merchants);
        }
        return "merchants_info";
    }

    /**
     * @param @param  did
     * @param @return 参数
     * @return String    返回类型
     * @throws
     * @Title: domerchantsdel_method
     * @Description: 审核商家
     */
    @RequestMapping("merchantsupst")
    @ResponseBody
    public Boolean domerchantsupst_method(Integer upid, Integer sta) {
        int flag = merchantsService.merchantsupst(upid, sta);
        if (flag > 0) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * @param @return 参数
     * @return String    返回类型
     * @throws
     * @Title: domerchants_init
     * @Description: 删除商家方法
     */
    @RequestMapping("domerchantsdel")
    @ResponseBody
    public Boolean domerchantsdel_method(Integer delid) {
        int flag = merchantsService.deleteByPrimaryKey(delid);
        if (flag > 0) {
            return true;
        } else {
            return false;
        }
    }

}
